package com.dtf.admin.button.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.dtf.admin.button.form.ButtonForm;
import com.dtf.admin.button.vo.SystemButton;
import com.dtf.admin.menu.service.SystemMenuService;
import com.dtf.core.common.utils.Const;

@Controller
@RequestMapping("/admin/button")
@SuppressWarnings("all")
public class ButtonController {
	@Resource
	private SystemMenuService menuService;

	@ResponseBody
	@RequestMapping("addButton")
	public Map addButton(HttpServletRequest request,
			HttpServletResponse response,
			RedirectAttributes redirectAttributes, ButtonForm form) {
		SystemButton systemButton = form.getSystemButton();
		systemButton.setBtn_id(Const.getUUID());
		menuService.add(systemButton);
		
		Map obj = new HashMap();
		obj.put("msg", "新增成功");
		obj.put("obj", systemButton);
		return obj;
	}
	
	@ResponseBody
	@RequestMapping("updateButton")
	public Map updateButton(HttpServletRequest request,
			HttpServletResponse response,
			RedirectAttributes redirectAttributes, ButtonForm form) {
		SystemButton systemButton = form.getSystemButton();
		menuService.edit(systemButton);
		Map obj = new HashMap();
		obj.put("msg", "更新成功");
		obj.put("obj", systemButton);
		return obj;
	}
	
	@ResponseBody
	@RequestMapping("deleteButton")
	public Map deleteButton(HttpServletRequest request,
			HttpServletResponse response,
			RedirectAttributes redirectAttributes, String btnId) {
		SystemButton button = new SystemButton();
		button.setBtn_id(btnId);
		menuService.delete(button);
		Map obj = new HashMap();
		obj.put("msg", "删除成功");
		return obj;
	}
	
	@ResponseBody
	@RequestMapping("loadButtonForID")
	public SystemButton loadButtonForID(HttpServletRequest request,
			HttpServletResponse response,String buttonId) {
		SystemButton button = new SystemButton();
		button.setBtn_id(buttonId);
		return (SystemButton) menuService.get(button);
	}
	
	
}
